home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13295 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: solon.com!not-for-mail
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
  4. Subject: Re: C coding problem
  5. Date: 6 Apr 1996 08:57:45 -0600
  6. Organization: XS4ALL, networking for the masses
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4k60p9$ahr@solutions.solon.com>
  10. References: <4j06na$808@solutions.solon.com> <4jttan$3gf@solutions.solon.com> <4jv6st$crf@solutions.solon.com> <4k1qh3$5hn@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: NN version 6.5.0 #666 (NOV)
  13.  
  14. news@Thinkage.On.CA writes:
  15.  
  16. >In article <4jv6st$crf@solutions.solon.com> schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz) writes:
  17. >>
  18. >>|> a[i] is converted to *(a + i) by the compiler in any case so
  19. >>|> whats the advantage with your approach?
  20. >>
  21. >>The machine doesn't have to add, the machine doesn't have to multiply,
  22. >>*a is less complicated to understand than a [i] since only one variable
  23. >>is involved, *a is more type safe than a [i], since there is nothing
  24. >>constraining i (besides it being of integral type), the optimizer
  25. >>has less to do, compile time decreases, etc. 
  26.  
  27. >However it is not always so that the machine does a distinct
  28. >add or multiply in order to handle a[i].  The "*p++" idiom may look
  29. >shot in the C code, and on a PDP-11 it usually resulted in nice
  30. >short code.  However, there is no guarentee that this is true of all
  31. >hardware.  It is not all that uncommon to have an architecture where
  32. >adding 1 to an int is much cheaper than adding one to a pointer,
  33.  
  34. Name three.
  35.  
  36. >In such and environment, 
  37. >      *q++ = *p++;
  38. >loses badly to
  39. >      q[i] = p[i], ++i;
  40. >if the hardware indexing works in terms of the objects being
  41. >referenced.
  42.  
  43. Even if you could name three such architectures, it doesn't mean
  44. that your 'winning' code loses on 99% of computers in the world.
  45. Besides, who (except for an absolute beginner) would code this:
  46.  
  47. void loserstrcpy(char p[],char q[])
  48. {  int i=0;
  49.  
  50.    while((q[i]=p[i])!=0)
  51.       i++;
  52. }
  53.  
  54. Frank
  55. --
  56. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  57. ------------------------------------------------------------------------
  58. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  59.